package com.muc.view.ext;

import javax.swing.*;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableColumn;
import java.awt.*;
import java.util.Vector;

public class MainViewTable extends JTable {
    public MainViewTable(){
        //设置表头
        JTableHeader tableHeader = getTableHeader();
        tableHeader.setFont(new Font(null, Font.BOLD, 16));
        tableHeader.setForeground(Color.RED);
        //设置表格体
        setFont(new Font(null, Font.PLAIN, 14));
        setForeground(Color.black);
        setGridColor(Color.BLACK);
        setRowHeight(30);
        //设置多行选择
        getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    }

    /*public void setDataModel(MainViewTableModel mainViewTableModel){
        this.setModel(mainViewTableModel);
    }*/

    public void renderRule(){
        //设置表格列的渲染方式
        Vector<String> strings = MainViewTableModel.getColums();
        MainViewCellRender render = new MainViewCellRender();
        for (int i = 0; i < strings.size(); i++) {
            TableColumn tableColumn = getColumn(strings.get(i));
            tableColumn.setCellRenderer(render);//设置渲染方式
            if (i == 0) {
                tableColumn.setPreferredWidth(80);//让第一列窄一点
                tableColumn.setMaxWidth(100);
                tableColumn.setResizable(false);//宽度不可以改变
            }
        }
    }
}
